package cn.sptpc.servlet;

import cn.sptpc.entity.web.LoginEntity;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/exit.do")
public class ExitServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getSession().removeAttribute("user");
        LoginEntity entity = new LoginEntity();
        Gson gson = new Gson();
        if (req.getSession().getAttribute("user") == null){
            entity.setCode(0);
        }else {
            entity.setCode(1);
        }
        resp.getWriter().print(gson.toJson(entity));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
